package com.liyuanjinglyj.csdncard.slice;

import com.liyuanjinglyj.csdncard.ResourceTable;
import com.liyuanjinglyj.csdncard.WebViewPage;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.webengine.WebView;
import ohos.agp.utils.Color;
import ohos.agp.window.service.WindowManager;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;
import ohos.utils.zson.ZSONObject;

public class WebViewPageSlice extends AbilitySlice {
    private static final HiLogLabel TAG = new HiLogLabel(HiLog.DEBUG, 0x0, WebViewPageSlice.class.getName());
    private WebView webView;
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_web_view_page);
        this.webView=(WebView)findComponentById(ResourceTable.Id_ability_web_view_page_webview);
        WindowManager.getInstance().getTopWindow().get().setStatusBarColor(Color.BLUE.getValue()); // 设置状态栏颜色
        getWindow().addFlags(WindowManager.LayoutConfig.MARK_TRANSLUCENT_STATUS);//沉浸式状态栏
        if(intent != null) {
            HiLog.info(TAG, String.valueOf(1111));
            String param = intent.getStringParam("params");//从intent中获取 跳转事件定义的params字段的值
            String url = "";
            if(param !=null){
                ZSONObject data = ZSONObject.stringToZSON(param);
                url = data.getString("url");
            }

            HiLog.info(TAG, url);
            this.webView.getWebConfig().setJavaScriptPermit(true);
            this.webView.load(url);
        }else{
            HiLog.info(TAG, String.valueOf(2222));
        }
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
